from javax.swing import JButton
from javax.swing import JFrame
from javax.swing import JPanel
from javax.swing import JTextField
from javax.swing import JMenu
from javax.swing import JMenuBar
from javax.swing import JMenuItem
from javax.swing import JComboBox
from java.awt import Color
from javax.swing import JList
from java.awt.event import KeyListener, ActionListener
import maintest


class GUI(JFrame):
    def __init__(self):
        super(GUI, self).__init__()
        self.initUI()        

    def initUI(self):        
        panel = JPanel()
        self.artists = [ "Bob Marley", "Coldplay", "Kanye West", "Michael Jackson" ]       
        menu = Menu()        
        searchbar = SearchBar()       
        getter = ArtistGetter(self)
        self.artistmenu = JComboBox(self.artists)
        self.artistmenu.addActionListener(getter)
        self.artistmenu.setBounds(100, 120, 350, 30)
        panel.add(self.artistmenu)        
        outputlist = makeOutputList()       
        self.getContentPane().add(panel)
        self.setJMenuBar(menu.makeMe())       
        panel.add(searchbar.makeMe())        
        panel.add(outputlist.makeMe())
        button = JButton("Search", actionPerformed=searchbar.getSearch)
        button.setBounds(370, 90, 100, 30)
        panel.add(button)
        panel.setLayout(None)  
        self.setTitle("Favorite Song Database")
        self.setSize(615, 400)
        self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
        self.setLocationRelativeTo(None)
        self.setVisible(True)
        self.setResizable(False)
        panel.setBackground(Color.GREEN) 
    
class ArtistGetter(ActionListener):
    def __init__(self, frame):
        self.outer = frame
    
    def actionPerformed(self, e):
        ret = self.outer.artistmenu.getSelectedItem()
        print(ret)

class Menu(JMenuBar):
    def __init__(self):        
        self.menu = JMenuBar()
        self.file = JMenu('File')
        self.add = JMenuItem('Add')
        self.remove = JMenuItem('Remove')
        
    def makeMe(self):       
        self.menu.add(self.file)
        self.file.add(self.add)
        self.file.add(self.remove)
        return self.menu            

    
class SearchBar(JTextField, KeyListener):    
    def __init__(self):         
        self.searchbar = JTextField()              
       
    def makeMe(self):                       
        self.searchbar.setBounds(100, 90, 270, 30)         
        return self.searchbar      

    def getSearch(self, e):
        print(self.searchbar.getText())
        self.searchbar.getText()              
       

        
class makeOutputList(JList): 
    def __init__(self):
        self.outputlist = JList( [ "Bob Marley", "Coldplay", "Kanye West", "Michael Jackson" ])      
        
    def makeMe(self):        
        self.outputlist.setBounds(100, 190, 370, 90)
        return self.outputlist
    
    def getSelectedOutput(self):
        print(self.outputlist.getSelectedValue())
        return(self.ouputlist.getSelectedValue())        
        
        
if __name__ == '__main__':
    GUI()
    Main= maintest
    Main.Data.createInitialDatabase()
   
    